package com.ynny.dao;

import com.ynny.entity.student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class studentDaolmpl implements studentDao{
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Override
    public student selectByPrimaryKey(String username) {
        String sql = "select * from student where username = ?";
        List<student> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(student.class), username);
        if (list.size() > 0) {
            return list.get(0);
        }
        return list.get(0);
    }

    @Override
    public int insert(student student) {
        String sql = "insert into student(username,password) values(?,?)";
        int i = jdbcTemplate.update(sql, student.getUsername(), student.getPassword());
        return i;
    }


}
